package com.example.mode.fragment;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.mode.R;
import com.example.mode.adapter.VideoAdapter;
import com.example.mode.beam.VideoData;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link VideosFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class VideosFragment extends Fragment {

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    public VideosFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment VideosFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static VideosFragment newInstance(String param1, String param2) {
        VideosFragment fragment = new VideosFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view =inflater.inflate(R.layout.fragment_videos, container, false);
        ViewPager2 viewPager2 = view.findViewById(R.id.videoViewPager);
        List<VideoData> videoData = new ArrayList<>();
        VideoData videoData1 = new VideoData();
        videoData1.videoURL = "https://sns-video-hw.xhscdn.com/stream/110/258/01e446389079250f0103730387b250855e_258.mp4";
        videoData1.videoTitle = "第一个视频";
        videoData1.videoSubtitle = "视频up主";
        videoData.add(videoData1);
        VideoData videoData2 = new VideoData();
        videoData2.videoURL = "https://sns-video-hw.xhscdn.com/stream/79/110/258/01e82c281178d24b4f03700196ec9cd787_258.mp4";
        videoData2.videoTitle = "第二个视频";
        videoData2.videoSubtitle = "视频up主";
        videoData.add(videoData2);
        VideoData videoData3 = new VideoData();
        videoData3.videoURL = "https://sns-video-hw.xhscdn.com/stream/1/110/258/01e8295b4c4918420103700196e1904832_258.mp4";
        videoData3.videoTitle = "第三个视频";
        videoData3.videoSubtitle = "视频up主";
        videoData.add(videoData3);
        VideoData videoData4 = new VideoData();
        videoData4.videoURL = "https://sns-video-hw.xhscdn.com/stream/110/258/01e725e4c776aec00103700192ec0ab8f6_258.mp4";
        videoData4.videoTitle = "第四个视频";
        videoData4.videoSubtitle = "视频up主";
        videoData.add(videoData4);
        VideoData videoData5 = new VideoData();
        videoData5.videoURL = "https://sns-video-hw.xhscdn.com/stream/79/110/258/01e784dcff7c54e24f037001945eff891a_258.mp4";
        videoData5.videoTitle = "第五个视频";
        videoData5.videoSubtitle = "视频up主";
        videoData.add(videoData5);
        VideoData videoData6 = new VideoData();
        videoData6.videoURL = "https://sns-video-hw.xhscdn.com/stream/110/258/01e4a3b0114545c401037603891f6b3af9_258.mp4";
        videoData6.videoTitle = "第六个视频";
        videoData6.videoSubtitle = "视频up主";
        videoData.add(videoData6);
        viewPager2.setAdapter(new VideoAdapter(videoData));
        return view;


    }
}